FROM docker.io/microsoft/dotnet AS build-env

RUN mkdir -p /app/out

USER root
WORKDIR /app

COPY . .

RUN cd TaoLeH.WebApi &&\
    dotnet publish -r debian.8-x64 -c release -o /app/out --disable-parallel


FROM docker.io/microsoft/dotnet:2.1-runtime

RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list &&\
    sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list

RUN apt update &&\
    apt install -y libunwind8-dev &&\
    apt-get clean

RUN mkdir /app /nonexistent &&\
    chown 65534:65534 /nonexistent &&\
    chown 65534:65534 /app

USER 65534
WORKDIR /app

COPY --from=build-env /app/out .

EXPOSE 8001/tcp

ENTRYPOINT ["dotnet", "TaoLeH.WebApi.dll"]

CMD ["--ASPNETCORE_ENVIRONMENT=Development"]
